package com.sicheng.lc.周赛.分类.模拟;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/23 21:29
 */
public class 文本编辑程序设计 {
    //https://leetcode.cn/contest/cmbchina-2022spring/problems/fWcPGC/

    public String deleteText(String article, int index) {

        if (article.charAt(index) == ' ')
            return article;
        int i = index + 1;
        for (; i < article.length(); i++) {
            if (article.charAt(i) == ' ') {
                break;
            }
        }
        int end = i;
        for (i = index - 1; i >= 0; i--) {
            if (article.charAt(i) == ' ')
                break;
        }
        if (i < 0) {
            i++;
        }

        if (end >= article.length())
            return article.substring(0, i);
        if (i == 0)
            return article.substring(end + 1);
        return article.substring(0, i) + article.substring(end);
    }

    public static void main(String[] args) {
        文本编辑程序设计 solution = new 文本编辑程序设计();
        System.out.println(solution.deleteText("Singing dancing in the rain", 10));
    }
}
